﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Debug</title>
    <script type="text/javascript">


    function trim(s) {
        return s ? s.replace(/^\s*|\s*$/g, '') : s;
    }

    function evaluate(s) {
//        var EL_PREFIX = "Data:";
//        if (!new RegExp("^\\s*" + EL_PREFIX).test(s))
//            return undefined;
        var properties = trim(s).split(/;/);
        var o = {};
        for (var k = 0; k < properties.length; k++) {
            var entry = properties[k];
            var index = entry.indexOf('=');
            if (index < 0)
                continue;
            var name = trim(entry.substring(0, index));
            var value = trim(entry.substring(index + 1));
            var root = name.substring(0, 1).toLowerCase();
            if (!o[root])
                o[root] = [];

            //sort
            var prop = {};
            prop[name] = value;
            o[root].push(prop);
        }
        var az = {};
        for (var i in o) {
            az[i.charCodeAt(0) - ('a').charCodeAt(0)] = o[i];
            
        }
        var rootAZ = {};
        for (var i = 0; i < 26; i++ ) {
            if (az[i] != undefined) {
                var tmp1 = az[i][0];
                var tmp = tmp1.substring(0,1);
                rootAZ[tmp]=az[i];
            }
        }
        return o;
    }
    //================================
    

function freshBySecond() {

        var myCookie = document.cookie + ";";
        var reversed = evaluate(myCookie);
        var ele = document.getElementById("myIDOne");
        if (ele != undefined && ele != null) {
            document.body.removeChild(ele);
        }
        document.body.innerHTML = createTable(reversed);
}

function createTable(para) {
    var result = "<table border='1' id='myIDOne'>";
    for (p in para) {
        result = result + "<tr>";
        result = result + "<td>";
        result = result + p;
        result = result + "</td>";
        for (s in para[p]) {
            for (k in para[p][s]) {
                result = result + "<td>";
                result = result + "<font color='blue'>";
                result = result + k;
                result = result + "</font>";
                result = result + "</td>";
                result = result + "<td>";
                result = result + para[p][s][k];
                result = result + "</td>";
            }
        }
        result = result + "</tr>";
    }
    result = result + "</table>";
    return result;
}

//+--------------------operate cookies-----------------------------------------



function GetCookie(name)
{
    var result = null;
    var myCookie = document.cookie + ";";
    var searchName = name + "=";
    var startOfCookie = myCookie.indexOf(searchName);
    var endOfCookie;
    if (startOfCookie != -1)
    {
        startOfCookie += searchName.length;
        endOfCookie = myCookie.indexOf(";",startOfCookie);
        result = unescape(myCookie.substring(startOfCookie, endOfCookie));
    }
    return result;
} 


function ClearCookie(name)
{
    var ThreeDays=3*24*60*60*1000;
    var expDate = new Date();
    expDate.setTime(expDate.getTime()-ThreeDays);
    document.cookie=name+"=;expires="+expDate.toGMTString();
}
//*------------------------------------------------------------------------
function toSetinterval() {
    lib.cookie.set("a", "1234", 30, "/", true);
    lib.cookie.set("b", "1234", 30, "/", true);
    lib.cookie.set("f", "ff34", 30, "/", true);
    lib.cookie.set("aad", "1234", 30, "/", true);
    lib.cookie.set("er", "1sdfs3e4", 30, "/", true);
    lib.cookie.set("zz", "1234", 30, "/", true);
    setInterval("freshBySecond()",2000);
}
    </script>
</head>
<body onload="toSetinterval()">

</body>
</html>
